#pragma GCC optimize("Ofast", "unroll-loops")
#include<bits/stdc++.h>
using namespace std; using ll = long long;
#define For(i, j, k) for ( int i = (j) ; i <= (k) ; i++ )
#define Fol(i, j, k) for ( int i = (j) ; i >= (k) ; i-- )
constexpr int inf = numeric_limits < int >::max() >> 1, dx[] = { 0, 0, 1, -1 }, dy[] = { 1, -1, 0, 0 };
using P = pair < int, int >;
#define fi first
#define se second
int n, m, k, x, y, xx, yy, o, sx, sy, tx, ty; vector < P > q, qq;
template < class T > struct A
{
	T data[6000009];
	inline T *operator[](int x) { return data + ( x - 1 ) * m; }
}; A < char > s; A < P > d;
inline int id(int x, int y) { return x * m - m + y; }
int main()
{
	freopen("stamp.in", "r", stdin), freopen("stamp.out", "w", stdout);
	cin.tie(nullptr) -> sync_with_stdio(false);
	cin >> n >> m >> k >> sx >> sy >> tx >> ty;
	For(i, 1, n) For(j, 1, m) cin >> s[i][j], d[i][j] = P(inf, inf);
	d[sx][sy] = P(0, k), q.emplace_back(sx, sy);
	for ( int dd = 0 ; q.size() ; dd++ )
	{
		qq = move(q), q.clear();
		for ( P i : qq ) if ( d[i.fi][i.se].fi == dd ) q.emplace_back(i);
		For(i, 0, (int)q.size() - 1)
		{
			x = q[i].fi, y = q[i].se;
			For(_, 0, 3)
			{
				xx = x + dx[_], yy = y + dy[_];
				if ( xx < 1 || xx > n || yy < 1 || yy > m || s[xx][yy] == '#' || d[xx][yy].fi != inf ) continue;
				d[xx][yy] = d[x][y], q.emplace_back(xx, yy);
			}
		}
		For(i, 0, (int)q.size() - 1)
		{
			x = q[i].fi, y = q[i].se;
			if ( d[x][y].fi == dd ) o = 1;
			else if ( d[x][y].se < k ) o = 2;
			else continue;
			For(_, 0, 1)
			{
				yy = y + dy[_];
				if ( yy < 1 || yy > m || d[x][yy].fi != inf ) continue;
				d[x][yy] = P(dd + 1, o == 1 ? 1 : d[x][y].se + 1), q.emplace_back(x, yy);
			}
		}
		For(i, 0, (int)q.size() - 1)
		{
			x = q[i].fi, y = q[i].se;
			if ( d[x][y].fi == dd ) o = 1;
			else if ( d[x][y].fi == dd + 1 && d[x][y].se < k ) o = 1;
			else if ( d[x][y].fi == dd + 1 && d[x][y].se == k && k != 1 ) o = 2;
			else if ( d[x][y].fi == dd + 1 && d[x][y].se > k && d[x][y].se < k + k ) o = 3;
			else continue;
			For(_, 2, 3)
			{
				xx = x + dx[_];
				if ( xx < 1 || xx > n || d[xx][y].fi != inf ) continue;
				d[xx][y] = P(dd + 1, o != 3 ? k + o : d[x][y].se + 1), q.emplace_back(xx, y);
			}
		}
	}
	return cout << d[tx][ty].fi << '\n', 0;
}